package com.peaksport.framework.metadata.sorter;

import java.io.Serializable;

import com.peaksport.framework.map.ListMap;
import com.peaksport.framework.util.PKPublicUtils;

/**
 */
@SuppressWarnings("serial")
public class SorterItemCollection implements Serializable {

    private ListMap<SorterItemInfo> col = new ListMap<>();

    public ListMap<SorterItemInfo> getCollection() {
        return col;
    }


    public void setCollection(ListMap<SorterItemInfo> col) {
        this.col = col;
    }
    public void addCollection(SorterItemCollection newCol) {
        if (newCol == null || newCol.isEmpty()) return;
        for (int i = 0, len = newCol.size(); i < len; i++) {
            SorterItemInfo sorterItemInfo = newCol.get(i);
            addSorterItemInfo(sorterItemInfo);
        }
    }

    public void addSorterItemInfo(SorterItemInfo sorterItemInfo) {
        if (sorterItemInfo == null || PKPublicUtils.isEmpty(sorterItemInfo.getProperyName())) 
        	return;
        col.add(sorterItemInfo.getProperyName(),sorterItemInfo);
    }

    public SorterItemInfo get(int index) {
        return col.get(index);
    }
    public SorterItemInfo get(String propertyName) {
        return col.get(propertyName);
    }

    public int size() {
        return col.size();
    }

    public boolean isEmpty() {
        return size() == 0;
    }

    public void clear() {
        col.clear();
    }

    public String toSQL() {
        StringBuilder sql = new StringBuilder();
        for (int i = 0, len = col.size(); i < len; i++) {
            SorterItemInfo sorterItemInfo = col.get(i);
            sql.append(sorterItemInfo.toSQL()) ;
            if (i != len -1) sql.append(",");
        }

        return  sql.toString();
    }

    @Override
    public String toString() {
        StringBuilder str = new StringBuilder();
        str.append("[");
        for (int i = 0,len = col.size(); i < len; i++) {
            SorterItemInfo sorterItemInfo = col.get(i);
            str.append(sorterItemInfo.toString());
            if (i != len - 1) str.append(",");

        }
        str.append("]");
        return str.toString();

    }


}
